﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A2DFramework.HttpLoadBalancer.Parsers.ConcreteParsers
{
    class HttpResponseParser : IHttpResponseParser
    {
        public HttpProtocal.HttpResponseEntity Parse(string rawHttpText)
        {
            if (rawHttpText == null || rawHttpText.Trim().Length == 0)
                return null;

            string headerString;
            string bodyString;
            string responseLineString;

            string[] parsedString = Helper.ParseHeaderBody(rawHttpText);

            responseLineString = parsedString[0];
            headerString = parsedString[1];
            bodyString = parsedString[2];

            HttpProtocal.HttpResponseEntity response = new HttpProtocal.HttpResponseEntity();


            response.ResponseLine = Helper.ParseResponseLine(responseLineString);
            response.HttpHeaders = Helper.ParseHeaders(headerString);


            //response.HttpBody = bodyString;

            return response;
        }
    }
}
